/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MyDate;

import java.io.*;
import javax.microedition.lcdui.*;
import sUtils.*;

/**
 *
 * @author thomas.s
 */
public class ImgRes {

    public Image meno_female = null;
    public Image meno_female2 = null;
    public Image meno_baby = null;
    public Image meno_baby2 = null;
    public Image menu = null;
    public int menu_w=0, menu_h=0;
    int menuRGB[] = null;

    public ImgRes()
    {
       int w,h; int [] rgb; Image img;
       try { 
           img = Image.createImage ("/meno_female.png");
           meno_female = Images.setOpacity(img, 0.80 );
           meno_female2 = Images.setOpacity(img, 0.40 );
           
       } catch (IOException e) { meno_female = null; }
       try { 
           img = Image.createImage ("/meno_baby.png");
           meno_baby = Images.setOpacity( img, 0.80 );
           meno_baby2 = Images.setOpacity( img, 0.40 );
       } catch (IOException e) { meno_baby = null; }

        try {
           Image menu_img = Image.createImage ("/mydate_menu.jpg");
           menu_w = menu_img.getWidth();
           menu_h = menu_img.getHeight();
           menuRGB = new int[menu_w*menu_h];
           menu_img.getRGB(menuRGB, 0, menu_w, 0, 0, menu_w, menu_h);
           int col, a;
           for ( int i=0; i<menu_w*menu_h; i++ )
           {
               col = menuRGB[i];
               a = (col&0xff)<<24;
               col = (col>>8)&0xff;

               menuRGB[i] = a | col | (col<<8) | (col<<16);
               //menuRGB[i] = 0x7fffffff;
           }
        } catch(Exception e) {}

    }

    public boolean updateMenu( Graphics g, int dd, int mm, int yy )
    {
        if (menuRGB==null) return false;
        menu = Image.createRGBImage(menuRGB, menu_w, menu_h, true);
        g.drawImage( menu, 0, g.getClipHeight()-menu_h, 0);
        Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        g.setColor(0xff000000);
        g.setFont(f);
        StringBuffer s = new StringBuffer(50);
        if (dd<10) s.append("0"); s.append(dd); s.append(".");
        if (mm<10) s.append("0"); s.append(mm); s.append(".");
        s.append(yy);
        String t = s.toString();
        g.drawString(t, (menu_w-f.stringWidth(t))/2+40, 700-f.getHeight()-10, 0);
        return true;
    }

    public int getKey( int x, int y, int w, int h )
    {
        if (y>=(h-menu_h) && y<h)
        {
            if (x>=120 && x<180) return -1; else
            if (x>=180 && x<400) return 2; else
            if (x>=400 && x<460) return 1;
        }
        return 0;
    }
}
